<template>
  <div>
    <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-form-model-item label="事件编码" prop="eventKey">
            <a-input v-model="form.eventKey" />
          </a-form-model-item>
          <a-form-model-item label="事件名称" prop="eventName">
            <a-input v-model="form.eventName" />
          </a-form-model-item>
          <a-form-model-item label="事件分类" prop="category">
              <a-input v-model="form.category" />
          </a-form-model-item>
          <a-form-model-item label="状态" prop="status">
            <a-radio-group v-model="form.status">
              <a-radio :value="1">
                启用
              </a-radio>
              <a-radio :value="0">
                禁用
              </a-radio>
            </a-radio-group>
          </a-form-model-item>
    </a-form-model>
  </div>
</template>
<script>

import { save } from '@/api/notifyEvent'
export default {
  name: 'NotifyEventForm',
  data() {
    return {
      labelCol: { span: 6 },
      wrapperCol: { span: 18 },
      form: {
        id: '',
        eventName: '',
        eventKey: '',
        category: '',
        status: 1
      },
      rules: {
        eventName: [{ required: true, message: '请输入事件名称', trigger: 'blur' }],
        eventKey: [{ required: true, message: '请输入事件编码', trigger: 'blur' }],
        category: [{ required: true, message: '请输入事件分类', trigger: 'blur' }]
      }
    }
  },
  methods: {
    onSubmit() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          console.log(this.form)
          save(this.form).then(res => {
            res.success ? this.$message.success('保存成功') : this.$message.error('保存失败')
            this.$emit('done', res.success)
          }).catch(res => {
            this.$emit('done', res.success)
          })
        } else {
          this.$emit('done', false)
          return false
        }
      })
    },
    resetForm() {
      // 重置表单数据
      this.$refs.ruleForm.resetFields()
      this.$utils.merge(this.form, this.$options.data()['form'])
    },
    async loadData(data) {
      if (data.id) {
        this.$utils.merge(this.form, data)
      }
    }
  }
}
</script>
